package com.mapull.list;

import java.util.*;

/**
 * 数组、列表 转换
 * @author mapull
 */
public class Array2List {

    public static void main(String[] args) {
//        toArray();
        toArray();
    }

    public static void getArray(){
        int[] numbers = new int[] {1, 2, 3, 4, 5};
        int lastNumber = numbers[-2];
    }

    private  static void getList() {
        List<String> list = new ArrayList<>();
        list.add("Tom");
        list.add(1, "Jerry");
        System.out.println(list.get(9));
    }
    private static void toArray(){
        List<String> list = Arrays.asList("A", "B", "C", "D", "D");
        System.out.println(list.get(9));
        String[] array = list.toArray(new String[0]);
        System.out.println(Arrays.toString(array));
    }

    private static void colToList(){
        Set<String> set = new HashSet<>();
        // 省略 set 初始化赋值
        List<String> list = new ArrayList<>(set);
        System.out.println(list);
    }

    private  static void forList(){
        List<String> list = new ArrayList<>();
        list.add("Tom");
        list.add(1,"Jerry");

        String removed = list.remove(5);
        System.out.println(removed);

        boolean dan = list.remove("Dan");
        System.out.println(dan);

        for(String str : list){
            System.out.println(str);
        }
    }
}
